package com.adong.springboot.controller;

import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.Map;

@Controller
@RequestMapping("/user")
public class LoginController {

    @PostMapping("/login")
    public String login(String userName, String passWord, Map<String, Object> map, HttpSession session) {
        if (!StringUtils.isEmpty(userName) && "adong".equals(userName) && "adong".equals(passWord)) {
            //防止表单提交,跳转到main页面,在跳转到dashboard
            session.setAttribute("user", userName);
            return "redirect:/main.html";
        } else {
            map.put("msg", "用户名密码错误");
            return "login";
        }

    }

}
